home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / k3d-makempeg < prev    next >
Encoding:
Text File  |  2004-07-23  |  3.5 KB  |  177 lines

  1. #!/bin/sh
  2.  
  3. # Cleanup gracefully after interrupts ...
  4. trap 'rm -f $parameter_file; echo "Terminating ..."; exit 1' INT TERM
  5.  
  6. function show_help
  7. {
  8.     cat << eof
  9.  
  10. Usage: k3d-makempeg [options] sourcedir output_file
  11.  
  12.   -h, --help         This message.
  13.   -v, --version      Prints program version and exits.
  14.   -f, --force        Overwrite output_file if it already exists.
  15.   -c, --compression  Set the amount of MPEG compression from 1
  16.                         (best quality) through 31 (smallest filesize) [1].
  17.   -p, --play         Play the compressed file when done.
  18.   -l, --loop         Loop file playback indefinitely.
  19.  
  20. eof
  21. }
  22.  
  23. compression=1
  24. force="no"
  25. play="no"
  26. loop="no"
  27.  
  28. while [ -n "$(echo $1 | grep '-')" ]; do
  29.     case $1 in
  30.         --help | -h)
  31.             show_help
  32.             exit;;
  33.  
  34.         --version | -v)
  35.             echo "\nk3d-makempeg version 0.4.2.1\n"
  36.             exit;;
  37.  
  38.         --force | -f)
  39.             force="yes"
  40.             shift;;
  41.         
  42.         --compression | -c)
  43.             compression=$2
  44.             shift 2;;
  45.  
  46.         --play | -p)
  47.             play="yes"
  48.             shift;;
  49.  
  50.         --loop | -l)
  51.             loop="yes"
  52.             shift;;
  53.  
  54.     esac
  55. done
  56.  
  57. source_dir=$1
  58. output_file=$2
  59.  
  60. if ! which ppmtompeg >/dev/null 2>/dev/null; then
  61.     cat << eof
  62.     
  63. Could not find ppmtompeg.  This script uses ppmtompeg to do
  64. the actual work of creating an MPEG file.  ppmtompeg is part
  65. of the NetPBM tools, available at http://netpbm.sourceforge.net
  66.  
  67. eof
  68.     exit 1
  69. fi
  70.  
  71. if ! which anytopnm >/dev/null 2>/dev/null; then
  72.     cat << eof
  73.  
  74. Could not find anytopnm.  This script uses anytopnm to convert
  75. source images into a format that can be compressed into an MPEG
  76. file.  anytopnm is part of the NetPBM tools, available at
  77. http://netpbm.sourceforge.net
  78.     
  79. eof
  80.     exit 1
  81. fi
  82.  
  83.  
  84. if [ -z "$source_dir" ]; then
  85.     echo -e "\nYou must specify the path to the source directory, use -h for help.\n" 1>&2
  86.     exit 1
  87. fi
  88.  
  89. if ! [ -e $source_dir ]; then
  90.     echo -e "\nSource directory [$source_dir] doesn't exist, use -h for help.\n" 1>&2
  91.     exit 1
  92. fi
  93.  
  94. if ! [ -d $source_dir ]; then
  95.     echo -e "\nSource directory [$source_dir] isn't a directory, use -h for help.\n" 1>&2
  96.     exit 1
  97. fi
  98.  
  99. if [ -z "$output_file" ]; then
  100.     echo -e "\nYou must specify the path to the output file, use -h for help.\n" 1>&2
  101.     exit 1
  102. fi
  103.  
  104. if [ -e $output_file ]; then
  105.     if [ "x$force" != "xyes" ]; then
  106.         echo -e "\nOutput file [$output_file] already exists, rerun with --force to overwrite, use -h for help.\n" 1>&2
  107.         exit 1
  108.     fi
  109. fi
  110.  
  111. parameter_file=/tmp/$$.ppmtompeg
  112.  
  113. cat > $parameter_file << eof
  114. PATTERN IBBPBBPBBPBBPBB
  115. FORCE_ENCODE_LAST_FRAME
  116. BASE_FILE_FORMAT PNM
  117. INPUT_CONVERT anytopnm 2>/dev/null *
  118. GOP_SIZE 30
  119. SLICES_PER_FRAME 1
  120. PIXEL HALF
  121. RANGE 2
  122. PSEARCH_ALG LOGARITHMIC
  123. BSEARCH_ALG SIMPLE
  124. IQSCALE $compression
  125. PQSCALE $compression
  126. BQSCALE $compression
  127. REFERENCE_FRAME ORIGINAL
  128. INPUT_DIR $source_dir
  129. INPUT
  130. $(ls -1 $source_dir)
  131. END_INPUT
  132. OUTPUT $output_file
  133. eof
  134.  
  135. ppmtompeg -no_frame_summary $parameter_file
  136.  
  137. rm -f $parameter_file
  138.  
  139. if [ "x$play" = "xyes" ]; then
  140.  
  141.     if which plaympeg >/dev/null 2>/dev/null; then    
  142.  
  143.         if [ "x$loop" = "xyes" ]; then
  144.  
  145.             playback="plaympeg -l $output_file"
  146.         
  147.         else
  148.  
  149.             playback="plaympeg $output_file"
  150.         
  151.         fi
  152.  
  153.     elif which xine >/dev/null 2>/dev/null; then
  154.     
  155.         if [ "x$loop" = "xyes" ]; then
  156.  
  157.             playback="xine --no-logo -ph -l $output_file"
  158.         
  159.         else
  160.  
  161.             playback="xine --no-logo -ph $output_file"
  162.         
  163.         fi
  164.  
  165.     fi
  166.     
  167.     if [ -z "$playback" ]; then
  168.         echo "\nCouldn't find a playback program, after trying plaympeg and xine.\n"
  169.         exit 1
  170.     fi
  171.     
  172.     $playback
  173.  
  174. fi
  175.  
  176.  
  177.